<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="whf.framework.security.UserContext" %>
<%@ page import="whf.framework.web.WebContextHolder" %>
<%@ page import="whf.framework.web.tag.TableColumn" %>
<jsp:directive.page import="whf.framework.web.tag.ext.TableAttributes"/>
<%@taglib uri="/WEB-INF/tlds/framework.tld" prefix="framework"%>
<%@taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
<%
UserContext userContext = WebContextHolder.getWebContext(request).getUserContext();
String tableId = request.getParameter("tableId");
TableAttributes attributes = userContext.getTableAttributes(tableId);
List columns = attributes.getTableColumns();
if("save".equals(request.getParameter("actionType"))){
try{
	String properties[] = request.getParameterValues("column");
	for(int i=0; columns != null && i<columns.size(); i++){
		TableColumn col = (TableColumn)columns.get(i);
		boolean found = false;
		for(int j=0; properties != null && j < properties.length; j++){
			if(whf.framework.util.StringUtils.equals(properties[j], col.getProperty())){
				found = true;
				col.setVisible(true);
				break;
			}
		}
		if(!found){
			col.setVisible(false);
		}
	}
	out.println("<script language='javascript'>");
	out.println("window.opener.location.reload(true);");
	out.println("</script>");
}catch(Exception e){
	e.printStackTrace();
}
}
%>
<%
if(columns == null){
%>
<script language="javascript">
alert('<bean:message key="framework.customize_columns.table_not_found" />');
window.close();
</script>
<%
	return;
}
String selectedValues = "";
for(int i=0; i<columns.size(); i++){
	TableColumn col = (TableColumn)columns.get(i);
	if(col.isVisible()){
		if(selectedValues.equals("")){
			selectedValues = col.getProperty();
		} else {
			selectedValues += ";"+col.getProperty();
		}
	}
}
pageContext.setAttribute("columns", columns);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/common/inc/select.jsp" %>
</head>
<body>
<form name="form1" action="#" method="post">
<input type="hidden" name="actionType" value="save" >
<input type="hidden" name="tableId" value='<framework:attr source="tableId" />' >

<table align="center" width="95%">
<tr><td>
选择列：
</td></tr>
<tr><td>
<div scroll="auto" height="350">
<framework:selections selectionName="column" source="columns" valueProperty="property" textProperty="displayTitle" 
	multiSelect="true" selectedValues="<%= selectedValues %>" rowCount="12" />
</div>
</td></tr>
<tr><td>
<input type="submit" value="确定" >
<input type="button" value="关闭" onclick="window.close();">
</td></tr>
</table>
</form>
</body>
</html>